<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="深入浅出Docker笔记, 博客">
    <meta name="description" content="个人学习储备知识与经验的秘密基地">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->

<script async src="https://www.googletagmanager.com/gtag/js?id=G-KDXT8Y4CLW"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag() {
        dataLayer.push(arguments);
    }

    gtag('js', new Date());
    gtag('config', 'G-KDXT8Y4CLW');
</script>


    <title>深入浅出Docker笔记 | 不二博客</title>
    <link rel="icon" type="image/png" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/favicon.png">

    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/css/matery.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/css/my.css">

    <script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 6.3.0">
<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
<link rel="alternate" href="/atom.xml" title="不二博客" type="application/atom+xml">
</head>




<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">不二博客</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">不二博客</div>
        <div class="logo-desc">
            
            个人学习储备知识与经验的秘密基地
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/weiyouwozuiku" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/weiyouwozuiku" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    
<script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/cryptojs/crypto-js.min.js"></script>
<script>
    (function() {
        let pwd = '';
        if (pwd && pwd.length > 0) {
            if (pwd !== CryptoJS.SHA256(prompt('请输入访问本文章的密码')).toString(CryptoJS.enc.Hex)) {
                alert('密码错误，将返回主页！');
                location.href = '/';
            }
        }
    })();
</script>




<div class="bg-cover pd-header post-cover" style="background-image: url('https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@src/source/_posts/PageImg/云计算/docker.jpeg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">深入浅出Docker笔记</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/Docker/">
                                <span class="chip bg-color">Docker</span>
                            </a>
                        
                            <a href="/tags/Book/">
                                <span class="chip bg-color">Book</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/%E4%BA%91%E8%AE%A1%E7%AE%97/" class="post-category">
                                云计算
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2019-12-22
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2022-06-10
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    4.7k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    17 分
                </div>
                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/prism/prism.css">
        

        
        <!-- 代码块折行 -->
        <style type="text/css">
            code[class*="language-"], pre[class*="language-"] { white-space: pre-wrap !important; }
        </style>
        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h2 id="第一章-容器发展之路">第一章 容器发展之路<a class="anchor" href="#第一章-容器发展之路">¶</a></h2>
<p>运营成本:OPEX</p>
<p>资金性支出:CAPEX</p>
<p>容器模型与虚拟机的区别：容器的运行不会独占操作系统。运行在相同宿主主机上的容器是共享一个操作系统，节省大量的系统资源，节省在许可证上的花销，以及为OS打补丁等运维成本。启动快，便于迁移。</p>
<p style="filter: opacity(95%);transform:scale(0.85);text-align:center;"><img src="https://math.now.sh?from=%E5%AF%B9%E5%AE%B9%E5%99%A8%E5%BD%B1%E5%93%8D%E8%BE%83%E5%A4%A7%E7%9A%84%E6%8A%80%E6%9C%AF%5Cbegin%7Bcases%7D%20%E5%86%85%E6%A0%B8%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4%28Kernel%20%5Cquad%20Namespace%29%20%5C%5C%5C%20%E6%8E%A7%E5%88%B6%E7%BB%84(Control%20%5Cquad%20Group)%20%5C%5C%5C%20%E8%81%94%E5%90%88%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F(Union%20%5Cquad%20File%20%5Cquad%20System)%20%5C%5C%5C%20Docker%20%20%5Cend%7Bcases%7D%0A"></p><p>运行中的容器共享主机的内核。</p>
<p>Kubernetes提供热插拔的容器运行时接口CRI。默认容器为Docker。</p>
<h2 id="第二章-走进Docker">第二章 走进Docker<a class="anchor" href="#第二章-走进Docker">¶</a></h2>
<p>Docker是一种运行在Linux和Win上的软件，用于创建、管理和编排容器。</p>
<p>Docker引擎是用于运行和编排容器的基础设施工具，是运行容器的核心容器运行时。</p>
<p>Docker版本号遵循<code>YY.MM-xx</code>格式。</p>
<p>Docker公司的一个核心哲学通常称为"含电池，但可拆卸"(Batteries included but removable)。即许多Docker内置的组件都可以替换为第三方组件。</p>
<p>OCI(开放容器计划)是CoreOS和Docker共同成立的管理委员会，发布镜像规范和运行时规范。</p>
<h2 id="第三章-Docker安装">第三章 Docker安装<a class="anchor" href="#第三章-Docker安装">¶</a></h2>
<h4 id="Win版Docker">Win版Docker<a class="anchor" href="#Win版Docker">¶</a></h4>
<ul>
<li>属于社区版，并不适用于生产环境。</li>
<li>通过启动一个独立的引擎来提供Docker环境。</li>
<li>某些版本特性可能延迟支持，稳定性第一，新特性其次。</li>
</ul>
<h4 id="Mac版Docker">Mac版Docker<a class="anchor" href="#Mac版Docker">¶</a></h4>
<ul>
<li>属于社区版，并不是为了生产环境进行设计的。</li>
<li>运行在一个轻量级的Linux VM之上。</li>
</ul>
<h4 id="Linux版Docker">Linux版Docker<a class="anchor" href="#Linux版Docker">¶</a></h4>
<p style="filter: opacity(95%);transform:scale(0.85);text-align:center;"><img src="https://math.now.sh?from=%5Cbegin%7Bcases%7D%5Ctext%7B%E7%A4%BE%E5%8C%BA%E7%89%88%28Community%20Edition%29%7D%20%5C%5C%20%5Ctext%7B%E4%BC%81%E4%B8%9A%E7%89%88(Enterprise%20Edition)%7D%5Cend%7Bcases%7D%0A"></p><p>Docker EE包含Docker CE中的全部功能，还包括了商业支持和其他Docker产品的集成。</p>
<p>使用shell脚本的安装步骤如下：</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">wget</span> -qO- https://get.docker.com/ <span class="token operator">|</span> <span class="token function">sh</span>
<span class="token comment"># 将用户加入Docker Unix组，通过非root用户使用Docker</span>
<span class="token function">sudo</span> <span class="token function">usermod</span> <span class="token parameter variable">-aG</span> <span class="token function">docker</span> your-name
<span class="token comment"># 查看是否添加到docker组成功，执行完毕需要重新登录，组权限才能生效</span>
<span class="token function">cat</span> /etc/group <span class="token operator">|</span> <span class="token function">grep</span> <span class="token function">docker</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>查看docker版本：</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">docker</span> <span class="token parameter variable">--version</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>查看docker信息：</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">docker</span> system info<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>设置docker开机自启：</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">sudo</span> systemctl <span class="token builtin class-name">enable</span> <span class="token function">docker</span>
<span class="token function">sudo</span> systemctl is-enabled <span class="token function">docker</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<p>检查确保docker的容器和服务都已经重启成功：</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">docker</span> container <span class="token function">ls</span>
<span class="token function">docker</span> <span class="token function">service</span> <span class="token function">ls</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<h4 id="升级Docker引擎">升级Docker引擎<a class="anchor" href="#升级Docker引擎">¶</a></h4>
<p>升级关键步骤：</p>
<ol>
<li>确保容器配置了正确的重启策略；在Swarm Mode模式下使用服务时，需要正确配置了draining node。</li>
<li>停止Docker守护程序</li>
<li>移除旧版本Docker</li>
<li>安装新版本Docker</li>
<li>配置新版本的Docker为开机自启动</li>
<li>确保容器重启成功</li>
</ol>
<h4 id="Docker存储驱动的选择">Docker存储驱动的选择<a class="anchor" href="#Docker存储驱动的选择">¶</a></h4>
<p>每个Docker容器都有一个本地存储空间，用于保存层叠的镜像层(Image Layer)以及挂载的容器文件系统。默认情况下，容器的所有读写操作发生在其镜像层上或挂载的文件系统中。</p>
<p>存储驱动在上层抽象设计中都采用了栈式镜像层存储和写时复制(Copy-on-Write)的设计思想。</p>
<p>存储驱动对Docker的性能和稳定性至关重要。</p>
<p>在Linux上，Docker可选择的一些存储驱动包括AUFS(最原始也是最老的)、Overlay2(可能是未来最佳选择)、Device Mapper、Btrfs和ZFS。</p>
<p>在Win上，Docker只支持Windows Filter一种存储驱动。</p>
<p>存储驱动的选择是节点级别的。即，每个docker主机只能选择一种存储驱动。不能为每个容器选择不同的存储驱动。在Linux上，修改<code>/etc/docker/deamon.json</code>文件来修改存储引擎配置。*修改完之后需要重启Docker才能生效。*如：</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token punctuation">{</span>
	<span class="token string">"storage-driver"</span><span class="token builtin class-name">:</span><span class="token string">"overlay2"</span>
<span class="token punctuation">}</span>
<span class="token comment"># 如果配置所在行不是最后一行，则需要在行尾添加逗号。</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre>
<p>如果修改了正在运行的docker主机的存储引擎类型，则现有的镜像和容器在重启之后将不可用，因为每种存储驱动在主机上存储镜像层的位置不一样(通常在/var/lib/<storage-driver>/…目录下)。</storage-driver></p>
<p>修改了存储驱动的类型，docker就无法找到原有的镜像和容器。切换回原本的存储驱动能继续使用之前的镜像和容器。如果在切换存储引擎之后，还想使用之前的镜像和容器，则需要将镜像保存为Docker格式，上传到某个镜像仓库，修改本地Docker引擎并重启，之后从镜像仓库将镜像拉取到本地，最后重启容器。</p>
<p>检查Docker当前的存储驱动类型：<code>docker system info</code>。</p>
<p>版本推荐选择：</p>
<ul>
<li>Red Hat Enterprise Linux：4.x版本内核或更高版本+Docker 17.06版本或更高版本，建议使用Overlay2。</li>
<li>Red Hat Enterprise Linux:低版本内核或低版本的Docker，建议使用Device Mapper。</li>
<li>Ubuntu Linux:4.x版本内核或更高版本，建议使用Overlay2。</li>
<li>Ubuntu Linux:更早的版本建议使用AUFS。</li>
<li>SUSE Linux Enterprise Server:Btrfs。</li>
</ul>
<h4 id="Device-Mapper配置">Device Mapper配置<a class="anchor" href="#Device-Mapper配置">¶</a></h4>
<p>大部分Linux存储驱动不需要或需要很少的配置。</p>
<p>Device Mapper通常需要合理配置之后才能表现出良好的性能。</p>
<p>默认情况下，Device Mapper采用loopback mounted sparse file作为底层实现来为Docker提供存储支持。开箱即用，并不适用于生产环境，性能很差。</p>
<p>通过将底层修改为direct-lvm模式，可以获取更好的性能。这种规模下通过使用基于裸块设备(Raw Block Device)的LVM精简池(LVM thin pool)。暂时只能配置一个块设备，并且只有在第一次安装后才能设置生效。但是目前来说有一定的风险。</p>
<h4 id="Docker自动设置direct-lvm">Docker自动设置direct-lvm<a class="anchor" href="#Docker自动设置direct-lvm">¶</a></h4>
<p>如下步骤将Docker配置存储驱动为Device Mapper，并使用direct-lvm模式。</p>
<ol>
<li>
<p>将下面的存储驱动配置添加到<code>/etc/docker/daemon.json</code>当中。</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token punctuation">{</span><span class="token string">"storage-driver"</span><span class="token builtin class-name">:</span><span class="token string">"devicemapper"</span>
<span class="token string">"storage-opts"</span>:<span class="token punctuation">[</span>
	<span class="token string">"dm.directlvm_device=/dev/xdf"</span>, <span class="token comment"># 设置块设备的位置</span>
	<span class="token string">"dm.thinp_percent=95"</span>, <span class="token comment"># 设置镜像和容器允许适应的最大存储空间占比</span>
	<span class="token string">"dm.thinp_metapercent=1"</span>,<span class="token comment"># 设置元数据存储允许使用的存储空间大小</span>
	<span class="token string">"dm.thinp_autoextend_threshold=80"</span>,<span class="token comment"># 设置LVM自动扩展精简池的阈值</span>
	<span class="token string">"dm.thinp_autoextend_percent=20"</span>,<span class="token comment"># 当触发精简池自动扩容机制的时候，扩容大小应当占现有空间的比例</span>
	<span class="token string">"dm.directlvm_device_force=false"</span># 是否将块设备格式化为新的文件系统
<span class="token punctuation">]</span>
<span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
</li>
<li>
<p>重启Docker。</p>
</li>
<li>
<p>确认Docker已成功运行，并块设备配置被成功加载。</p>
</li>
</ol>
<p>即使Docker在direct-lvm模式下只能设置单一块设备，其性能显著优于loopback模式。</p>
<h4 id="Docker手动设置direct-lvm">Docker手动设置direct-lvm<a class="anchor" href="#Docker手动设置direct-lvm">¶</a></h4>
<p>前置知识：</p>
<ul>
<li>
<p>块设备(Block Device)</p>
<p>在使用direct-lvm模式的时候，需要有可用的块设备。这些块设备应该位于高性能的存储设备之上，如：SSD或外部LUN存储。</p>
</li>
<li>
<p>LVM配置</p>
<p>Docker的Docker Mapper存储驱动底层利用LVM(Logical Volume Manager)来实现，需要配置LVM所需的物理设备、卷组、逻辑卷和精简池。应当使用专用的物理卷并将其配置在相同的卷组中。这个卷组不应当被Docker之外的工作负载所使用。此外还需要配置额外两个逻辑卷，分别存储存储数据和源数据信息。另外要创建LVM配置文件、指定LVM自动扩容的触发阈值，以及自动扩容的大小，并且为自动扩容配置相应的监控，保证自动扩容会被触发。</p>
</li>
<li>
<p>Docker配置</p>
<p>修改Docker配置文件之前要先保存原始文件(etc/docker/daemon.json)，然后进行修改。</p>
</li>
</ul>
<h2 id="第四章-纵观Docker">第四章 纵观Docker<a class="anchor" href="#第四章-纵观Docker">¶</a></h2>
<h4 id="运维视角">运维视角<a class="anchor" href="#运维视角">¶</a></h4>
<p>Docker安装主要涉及两个组件：Docker客户端、Docker daemon。</p>
<p>deamon实现了Docker引擎的API。</p>
<p>Linux默认安装时，客户端和daemon之间的通信是通过本地IPC/UNIX Socket完成的(/var/run/docker.sock)。Windows通过名为npipe:////./pipe/docker_engine的管道完成的。</p>
<p>Docker镜像可以理解为一个包含了OS文件系统和应用的对象。</p>
<p>虚拟机模板本质上是处于关机状态的虚拟机。</p>
<p><code>docker image ls</code>：查看镜像。</p>
<p>拉取(pulling)：在Docker主机上获取镜像的操作。</p>
<p>Docker的每个镜像都有自己唯一的ID。用户可以通过引用镜像的ID或名称来使用镜像。如果用户选择使用镜像ID，通常只需要输入ID开头的几个字符即可。</p>
<p><code>docker container run -it + 镜像名 运行的进程</code>：从镜像中来启动容器。例如：<code>docker container run -it ubuntu:latest /bin/bash</code>或<code>docker container run -it microsoft/powershell:nanoserver pwsh.exe</code>。<code>it</code>参数：开启容器的交互模式并将Shell链接到容器终端。</p>
<p>按<code>Ctrl-PQ</code>组合键，<strong>可以在退出容器的同时还保持容器运行</strong>。</p>
<p><code>docker container ls</code>：查看系统内部处于运行状态的容器。-a参数可以列出所有容器，包括处于停止状态的。</p>
<p><code>docker container stop + 容器对应名称或ID</code>：停止容器运行</p>
<p><code>docker container rm + 容器对应名称或ID</code>：杀死容器</p>
<p><code>docker container exec</code>：将shell链接到一个运行中的容器终端。例如：<code>docker container exec -it 容器名称或者id bash</code>。</p>
<p><code>docker container start &lt;镜像ID&gt;</code>：启动镜像</p>
<h4 id="开发视角">开发视角<a class="anchor" href="#开发视角">¶</a></h4>
<p>每个仓库都包含一个名为Dockerfile文件，这是一个纯文本文件，描述了如何将应用构建到Docker镜像中。 每一行代表一个用于构建镜像的指令。</p>
<p><code>docker image build -t 镜像名 .</code> ：使用当前目录中的Dockerfile文件和应用代码创建新的镜像。构建时间长短是由构建过程中要拉取的镜像大小和复杂度决定的。</p>
<h2 id="第五章-Docker引擎">第五章 Docker引擎<a class="anchor" href="#第五章-Docker引擎">¶</a></h2>
<p>Docker引擎是用来运行和管理容器的核心软件，通常将其代指为Docker或Docker平台。</p>
<p>Docker引擎是模块化的。</p>
<p><img src="https://math.now.sh?inline=Docker%E5%BC%95%E6%93%8E%E7%BB%84%E4%BB%B6%5Cbegin%7Bcases%7DDocker%5Cquad%20Client%5C%5CDocker%5Cquad%20daemon%5C%5Ccontainerd%5C%5Crunc%5Cend%7Bcases%7D" style="filter: opacity(95%);transform:scale(0.85);text-align:center;display:inline-block;margin: 0;"></p>
<p><img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@src/source/_posts/%E4%BA%91%E8%AE%A1%E7%AE%97/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0_Docker%E5%BC%95%E6%93%8E.png" alt="深入浅出Docker笔记_Docker引擎.png"></p>
<p><img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@src/source/_posts/%E4%BA%91%E8%AE%A1%E7%AE%97/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0_Docker%E5%BC%95%E6%93%8E1.png" alt="深入浅出Docker笔记_Docker引擎1.png"></p>
<p>runc是OCi容器运行时规范的参考实现。实质上是一个轻量级的、针对Libcontainer进行了包装的命令行交互工具(Libcontainer取代了早起的LXC)。</p>
<p>runc只有一个功能就是<strong>创建容器</strong>。本质是一个独立的容器运行时工具。</p>
<p>containerd的主要任务是容器的生命周期管理，也可以进行镜像管理等。containerd组件确保了Docker镜像能够以之后以正确的OCI Bundle的格式传递给runc。</p>
<p>containerd在linux和windows中以daemon的方式运行。Kubernetes可以通过cri-containerd使用containerd。</p>
<p>Daemon使用一种CRUD风格的API，通过gRPC与containerd进行通信。</p>
<p>Daemon的主要功能包括镜像管理、镜像构建、REST API、身份验证、安全、核心网络、编排。</p>
<p>一旦Daemon接收到创建新容器的命令，就会向containerd发出调用。containerd指挥runc去做。containerd将Docker镜像转换成OCI bundle，并让runc基于此创建一个新的容器。runc与操作系统内核接口进行通信，基于所有必要的工具(Namespace、CGroup等)来创建容器。容器进程作为runc的子进程启动。启动完毕后，runc退出。</p>
<p><img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@src/source/_posts/%E4%BA%91%E8%AE%A1%E7%AE%97/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0_Docker%E5%90%AF%E5%8A%A8.png" alt="深入浅出Docker笔记_Docker启动.png"></p>
<p>将所有的用于启动、管理容器的逻辑和代码从daemon中移除，以为者容器运行时与Docker daemon是解耦的，称之为“无守护进程的容器”。因此，Docker daemon的维护和升级不会影响运行中的容器。</p>
<p>每次创建容器<code>shim</code>fork一个新的runc实例。一旦容器创建完毕，对应的runc进程退出。</p>
<p>一旦容器进程的父进程runc进程退出，相关联的containerd-shim进程就会成为容器的父进程。</p>
<p>shim的部分职责：1.保持所有STDIN和STDout流是开启的，从而当daemon重启时，容器不会因为管道的关闭而终止。2.将容器的退出状态反馈给daemon。</p>
<h2 id="第六章-Docker镜像">第六章 Docker镜像<a class="anchor" href="#第六章-Docker镜像">¶</a></h2>
<p>镜像由多层构成。内部是一个精简的操作系统，包括应用运行所必须的文件和依赖包。</p>
<p><code>docker container run</code>和<code>docker service create</code>命令从某个镜像启动一个或多个容器。</p>
<p>一旦容器从镜像启动后，二者之间变成相互依赖关系，并且在镜像上启动的容器全部停止之前，镜像是无法被删除的。</p>
<p>通常Docker镜像中只有一个精简的shell，甚至没有shell。镜像不包含内核，容器共享所在Docker主机的内核。</p>
<p>容器只包含必要的操作系统(通常只有操作系统文件和文件系统对象)。</p>
<p>Hyper-V容器运行在专业用的轻量级VM上，同时利用VM内部的操作系统内核。</p>
<p>Linux Docker主机本地镜像仓库通常位于<code>/var/lib/docker/\&lt;stroage-drivewr&gt;</code>，Windows Docker主机是<code>C:\ProgramData\docker\windowsfilter</code>。</p>
<p><code>docker image pull &lt;repository&gt;:&lt;tag&gt;</code>：拉取镜像。如果用户没有指定具体的镜像标签，默认拉取标签为latest的镜像。Docker镜像存储在镜像仓库服务中。客户端中的镜像仓库服务默认是使用Docker Hub。</p>
<p><strong>标签为latest的镜像并不一定是最新的，但是使用的时候依然要谨慎。</strong></p>
<p><code>docker image pull &lt;所有者&gt;/&lt;repository&gt;:&lt;tag&gt;</code>：拉取非官方的Docker hub仓库的镜像。</p>
<p><code>docker pull &lt;第三方镜像仓库服务的DNS名称&gt;/&lt;所有者&gt;/&lt;repository&gt;:&lt;tag&gt;</code>：从第三方仓库拉取镜像</p>
<p>以上拉取镜像的命令可以加-a参数，下载仓库中的全部镜像。如果镜像仓库中同时包含用于多个平台或者架构的镜像，那么命令可能会失败。</p>
<p>镜像仓库服务包含多个镜像仓库。一个镜像仓库包含多个镜像。</p>
<p>标签是存放在镜像元数据中的任意数字或字符串。一个镜像可以根据用户需要设置多个标签。</p>
<p>悬虚镜像：没有标签的镜像，在列表时显示为&lt;none&gt;:&lt;none&gt;。通常出现这种情况，是因为构建了一个新的镜像，然后为这个镜像打了一个已经存在的标签。Docker创建新的镜像，并赋予这个镜像标签。之前拥有这个标签的镜像会被移除这个标签。</p>
<p><code>docker image ls --filter dangling=true</code>：显示悬虚镜像。可以使用–format参数通过Go模板。–digest参数在本地查看镜像摘要。</p>
<p><code>docker image prune</code>：移除全部悬虚镜像。-a参数删除所有没有被任何容器使用的镜像。</p>
<p>Docker目前支持如下的过滤器：</p>
<ul>
<li>dangling：可以指定true或者false，仅返回悬虚镜像(true)，或非悬虚镜像(false)。</li>
<li>before：需要镜像名称或者ID作为参数，返回在之前被创建的全部镜像。</li>
<li>since：与before类似，不过返回的是指定镜像之后创建的全部镜像。</li>
<li>label：根据标注(label)的名称或者值，对镜像进行过滤。</li>
<li>其他过滤方式可以使用reference。例如：–filter=reference=“*:latest*”。</li>
</ul>
<p>使用<code>docker image ls --format "{{.Size}}"</code>或<code>docker image ls --format "{{.Repository}: {{.Tag}: {{.Size}}"</code>这个的format参数是Go模板对输出内容进行格式化。</p>
<p><code>docker search &lt;特定字符串&gt;</code>：搜索所有"NAME"字段中包含特定字符串的仓库。“NAME”字段是仓库名称，包含了Docker ID，或者非官方仓库的组织名称。–filter "is-official=true"参数使命令只显示官方镜像。–filter "is-automated=true"参数使命令只显示自动创建的仓库。–limit参数设置返回内容行数，默认25行，最多100行。</p>
<p><code>docker image inspect &lt;镜像名&gt;</code>：查看镜像层数据和元数据。</p>
<p><code>docker histoy</code>：显示镜像的构建历史记录，但其不是严格意义上的镜像分层。有些Dockerfile中的指令并不会创建新的镜像层。但是会在镜像中添加元数据。</p>
<p>所有的Docker镜像都起始于一个基础镜像层，当进行修改或增加新的内容时，就会在当前镜像之上，创建新的镜像层。</p>
<p>在添加额外的镜像层的同时，镜像始终保持是当前所有镜像的组合。</p>
<p>Docker采用快照机制实现镜像层堆栈，并保证多镜像层对外显示为统一的文件系统。</p>
<p><strong>多个镜像之间可以共享镜像层。</strong></p>
<p><strong>每个镜像都有一个基于其内容的密码散列值，也被称为摘要(digest)。</strong></p>
<p><code>docker image pull &lt;镜像名&gt;@&lt;sha256码&gt;</code>：通过镜像摘要拉取镜像。</p>
<p>镜像的唯一标识是一个加密ID，即配置对象本身的散列值。每个镜像层也由一个加密ID区分，其值为镜像层本身内容的散列值。也就是内容散列。</p>
<p><strong>每个镜像层在拉取或推送时，包含一个分发散列值，这是一个压缩版镜像的散列值。该散列值用于校验拉取的镜像是否被篡改过。</strong></p>
<p>为了实现多架构的方便使用，Docker的镜像仓库服务API支持两种重要的结构：Manifest列表(新)和Manifest。Manifest列表是指某个镜像标签支持的架构列表。其支持的每种架构，都有自己的Manifest定义。</p>
<p><img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@src/source/_posts/%E4%BA%91%E8%AE%A1%E7%AE%97/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0_Manifest%E5%88%97%E8%A1%A8.png" alt="深入浅出Docker笔记_Manifest列表.png"></p>
<p>Manifest列表是可选的。在没有Manifest列表的情况下，镜像仓库服务会返回普通的Manifest。</p>
<p><code>docker image rm &lt;镜像名或镜像ID&gt;</code>：删除镜像。</p>
<p>某个镜像层被多个镜像共享，那只有当全部依赖该镜像层的镜像都被删除，该镜像层才会被删除。</p>
<p><code>docker image ls -q </code>：返回当前docker主机中所有容器的ID。</p>
<p><code>docker image rm $ (docker image ls -q) -f</code></p>
<h2 id="第七章-Docker容器">第七章 Docker容器<a class="anchor" href="#第七章-Docker容器">¶</a></h2>
<h2 id="补充">补充<a class="anchor" href="#补充">¶</a></h2>
<p>镜像是一堆只读层的统一视角。</p>
<p><img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@src/source/_posts/%E4%BA%91%E8%AE%A1%E7%AE%97/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0_image-container.png" alt="深入浅出Docker笔记_image-container.png"></p>
<p>统一文件系统：将多个只读层重叠在一起，并整合成一个文件系统，对用户隐藏。</p>
<p>在一个运行的容器内部，相应的文件层是不可见的。</p>
<p><strong>容器和镜像几乎一样，也是一堆层的统一视角。唯一区别在于容器最上面的一层是可读可写的。即，容器=镜像+可读写层</strong></p>
<p>运行态容器：可读写的统一文件系统加上隔离的进程空间和包含其中的进程。</p>
<p><img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@src/source/_posts/%E4%BA%91%E8%AE%A1%E7%AE%97/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0_%E8%BF%90%E8%A1%8C%E6%80%81%E5%AE%B9%E5%99%A8.png" alt="深入浅出Docker笔记_运行态容器.png"></p>
<p>一个文件层包含多信息：1.元数据(metadata)：关于这个层的额外信息，它不仅能够让Docker获取运行和构建时的信息，还包括父层的层次信息。**只读层和读写层都包含元数据。**2.指向父层的指针。如果没有这个指针，说明它处于最底层。3.id。</p>
<p><img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@src/source/_posts/%E4%BA%91%E8%AE%A1%E7%AE%97/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BADocker%E7%AC%94%E8%AE%B0_dockerrun.png" alt="深入浅出Docker笔记_dockerrun.png"></p>
<p><code>docker ps </code>：；列出所有运行中的容器，隐藏非运行态的容器。-a参数可以列出所有容器。</p>
<p>Docker主要解决了应用隔离、应用部署、资源限制。</p>
<p>其中隔离技术只要依靠的是Namespace，资源限制使用的是Cgroup。</p>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">不二</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="http://buerlog.top/2019/12/22/yun-ji-suan/shen-ru-qian-chu-docker-bi-ji/">http://buerlog.top/2019/12/22/yun-ji-suan/shen-ru-qian-chu-docker-bi-ji/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">不二</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/Docker/">
                                    <span class="chip bg-color">Docker</span>
                                </a>
                            
                                <a href="/tags/Book/">
                                    <span class="chip bg-color">Book</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2019/12/27/qian-ru-shi/shu-mei-pai-kai-fa-ji-lu/">
                    <div class="card-image">
                        
                        <img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@src/source/_posts/PageImg/嵌入式/raspberry.jpg" class="responsive-img" alt="树莓派开发记录">
                        
                        <span class="card-title">树莓派开发记录</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2019-12-27
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" class="post-category">
                                    嵌入式
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/%E6%A0%91%E8%8E%93%E6%B4%BE/">
                        <span class="chip bg-color">树莓派</span>
                    </a>
                    
                    <a href="/tags/%E5%BC%80%E5%8F%91/">
                        <span class="chip bg-color">开发</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2019/12/12/jing-yan-zong-jie/manjaro-an-zhuang-ji-qi-pei-zhi/">
                    <div class="card-image">
                        
                        <img src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@src/source/_posts/PageImg/经验总结/manjaro.jpg" class="responsive-img" alt="Manjaro系统配置">
                        
                        <span class="card-title">Manjaro系统配置</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2019-12-12
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E7%BB%8F%E9%AA%8C%E6%80%BB%E7%BB%93/" class="post-category">
                                    经验总结
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/%E8%A3%85%E6%9C%BA/">
                        <span class="chip bg-color">装机</span>
                    </a>
                    
                    <a href="/tags/Ranger/">
                        <span class="chip bg-color">Ranger</span>
                    </a>
                    
                    <a href="/tags/Manjaro/">
                        <span class="chip bg-color">Manjaro</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('120')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: 不二博客<br />'
            + '文章作者: 不二<br />'
            + '文章链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4, h5, h6'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4, h5, h6').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="song"
                   id="1901371647"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/aplayer/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

    
    <div class="container row center-align" style="margin-bottom: 15px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2018-2023</span>
            
            <span id="year">2018</span>
            <a href="/about" target="_blank">不二</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">263.4k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <span id="sitetime">载入运行时间...</span>
            <script>
                function siteTime() {
                    var seconds = 1000;
                    var minutes = seconds * 60;
                    var hours = minutes * 60;
                    var days = hours * 24;
                    var years = days * 365;
                    var today = new Date();
                    var startYear = "2018";
                    var startMonth = "5";
                    var startDate = "25";
                    var startHour = "17";
                    var startMinute = "20";
                    var startSecond = "53";
                    var todayYear = today.getFullYear();
                    var todayMonth = today.getMonth() + 1;
                    var todayDate = today.getDate();
                    var todayHour = today.getHours();
                    var todayMinute = today.getMinutes();
                    var todaySecond = today.getSeconds();
                    var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                    var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                    var diff = t2 - t1;
                    var diffYears = Math.floor(diff / years);
                    var diffDays = Math.floor((diff / days) - diffYears * 365);
                    var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
                    var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) /
                        minutes);
                    var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours -
                        diffMinutes * minutes) / seconds);
                    if (startYear == todayYear) {
                        document.getElementById("year").innerHTML = todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffDays + " 天 " + diffHours +
                            " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    } else {
                        document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffYears + " 年 " + diffDays +
                            " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    }
                }
                setInterval(siteTime, 1000);
            </script>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/weiyouwozuiku" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:weiyouwozuiku@gmail.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=1104891151" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 1104891151" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>





    <a href="https://www.zhihu.com/people/he-he-9-35-47" class="tooltipped" target="_blank" data-tooltip="关注我的知乎: https://www.zhihu.com/people/he-he-9-35-47" data-position="top" data-delay="50">
        <i class="fab fa-zhihu1">知</i>
    </a>



    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>

    <script src='https://unpkg.com/mermaid@8.14.0/dist/mermaid.min.js'></script>
    <script>
      if (window.mermaid) {
        mermaid.initialize({theme: 'forest'});
      }
    </script>
  

    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/materialize/materialize.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/aos/aos.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/js/matery.js"></script>

    <!-- Baidu Analytics -->

<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?943a68f473d421f2d98228f74edc63d0";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    
    <script async src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    
    <script type="text/javascript" color="0,0,255"
        pointColor="0,0,255" opacity='0.7'
        zIndex="-1" count="150"
        src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/background/canvas-nest.js"></script>
    

    
    
    <script type="text/javascript" size="150" alpha='0.6'
        zIndex="-1" src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/background/ribbon-refresh.min.js" async="async"></script>
    

    
    <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/background/ribbon-dynamic.js" async="async"></script>
    

    
    <script src="https://cdn.jsdelivr.net/gh/weiyouwozuiku/weiyouwozuiku.github.io@master/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
